package com.xianyun.site.iblog.user.executor.command;

import com.alibaba.cola.dto.Response;
import com.xianyun.site.iblog.domain.user.gateway.SocialUserGateway;
import com.xianyun.site.iblog.domain.user.model.SocialUser;
import com.xianyun.site.iblog.dto.user.SocialUserBindCmd;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.validation.Valid;

/**
 * 三方用户绑定执行
 * @author mac_zyj
 */
@Slf4j
@Component
public class SocialUserBindCmdExo {

    @Autowired
    private SocialUserGateway socialUserGateway;

    public Response execute(@Valid SocialUserBindCmd cmd){
        try {
            SocialUser bindUser = new SocialUser();
            bindUser.setUserId(cmd.getUserId());
            bindUser.setId(Integer.parseInt(cmd.getSocialId()));
            socialUserGateway.bindSocialUserAndUser(bindUser);
            return Response.buildSuccess();
        }catch (Exception exception){
            return Response.buildFailure("BIZ_SOCIAL_BIND_ERROR",exception.getMessage());
        }
    }
}
